// pages/shoplist/shoplist.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		query: {},
		shopList: [],
		page: 1,
		pageSize: 10,
		total: 0,
		isloading: false
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.setData({
			query: options
		})
		this.getShopList()
	},
	getShopList(cb) {
		console.log(this.data.query.id)
		this.setData({
			isloading: true
		})
		wx.showLoading({
			title: '数据加载中...',
		})
		wx.request({
			url: `https://www.escook.cn/categories/${this.data.query.id}/shops`,
			method: 'GET',
			data: {
				_page: this.data.page,
				_limit: this.data.pageSize
			},
			success: (res) => {
				console.log(res)
				this.setData({
					// shopList: [...this.data.shopList,...res.data],
					// total:res.header['X-Total-Count'] - 0
					shopList: [
						{id:1,name:'小龙虾1',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:2,name:'小龙虾2',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:3,name:'小龙虾3',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:4,name:'小龙虾4',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:5,name:'小龙虾5',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:6,name:'小龙虾6',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:7,name:'小龙虾7',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:8,name:'小龙虾8',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:9,name:'小龙虾9',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
						{id:10,name:'小龙虾10',phone:'13222222222',score:100,address:'仁让里村',businessHours:'今天09:00营业'},
					],
					total:80
				})
			},
			complete: () => {
				wx.hideLoading()
				this.setData({
					isloading: false
				})
				cb && cb()
			}
		})
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {
		wx.setNavigationBarTitle({
			title: this.data.query.title
		})
	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {
		this.setData({
			page: 1,
			shopList: [],
			total: 0
		})
		this.getShopList(()=>{
			wx.stopPullDownRefresh()
		})
	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {
		if(this.data.page * this.data.pageSize >= this.data.total) {
			return wx.showToast({
				title: '数据加载完毕！',
				icon: 'none'
			})
		}
		if(this.data.isloading) return
		this.setData({
			page: this.data.page + 1
		})
		this.getShopList()
	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})